import { IncomingHttpHeaders } from 'http'

export function getIp(headers: IncomingHttpHeaders): string | undefined {
  const result = headers['cf-connecting-ip']
    ?? headers['x-forwarded-for']
    ?? headers['x-real-ip']

  if (Array.isArray(result)) {
    return result[0]
  }

  return result
}